columnview: Update column positions on reordering
authorMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 16:40:32 +0000 (12:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 5 Jun 2020 17:28:44 +0000 (13:28 -0400)
Tell reordered columns to reorder their cells to
the new position. This is necessary to get things
like separators right. The visible symptom of this
problem was the lack of the right border when the
last column is reorder to another position, since
the title widget was still the last in its container,
so :last-child applied.

gtk/gtkcolumnview.c

index 46fb35714786eeba45ab00d1cf4ebaded5e1f28e..190a3ae0e9e75ef05741c0bb3be4b12129161f15 100644 (file)
@@ -1363,6 +1363,7 @@ gtk_column_view_insert_column (GtkColumnView       *self,
   g_return_if_fail (gtk_column_view_column_get_column_view (column) == NULL ||
                     gtk_column_view_column_get_column_view (column) == self);
   g_return_if_fail (position <= g_list_model_get_n_items (G_LIST_MODEL (self->columns)));
+  int old_position = -1;
 
   g_object_ref (column);
 
@@ -1377,16 +1378,20 @@ gtk_column_view_insert_column (GtkColumnView       *self,
           g_object_unref (item);
           if (item == column)
             {
+              old_position = i;
               g_list_store_remove (self->columns, i);
               break;
             }
         }
     }
-  else
-    gtk_column_view_column_set_column_view (column, self);
 
   g_list_store_insert (self->columns, position, column);
 
+  gtk_column_view_column_set_column_view (column, self);
+
+  if (old_position != -1 && position != old_position)
+    gtk_column_view_column_set_position (column, position);
+
   gtk_column_view_column_queue_resize (column);
 
   g_object_unref (column);